# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: site-packages\PyInstaller\utils\git.py
"""
This module contains various helper functions for git DVCS
"""
import os
from ..compat import exec_command, exec_command_rc, FileNotFoundError

try:
    WindowsError
except NameError:
    WindowsError = FileNotFoundError


def get_repo_revision():
    path = os.path
    gitdir = path.normpath(
        path.join(path.dirname(os.path.abspath(__file__)), "..", "..", ".git")
    )
    cwd = os.path.dirname(gitdir)
    if not path.exists(gitdir):
        try:
            from ._gitrevision import rev

            if not rev.startswith("$"):
                return "+" + rev
        except ImportError:
            pass

        return ""
        try:
            exec_command_rc("git", "update-index", "-q", "--refresh", cwd=cwd)
            recent = (
                exec_command("git", "describe", "--long", "--dirty", "--tag", cwd=cwd)
            ).strip()
            if recent.endswith("-dirty"):
                tag, changes, rev, dirty = recent.rsplit("-", 3)
                rev = rev + ".mod"
            else:
                tag, changes, rev = recent.rsplit("-", 2)
            if changes == "0":
                return ""
            return "+" + rev
        except (FileNotFoundError, WindowsError):
            pass

        return ""


if __name__ == "__main__":
    print(get_repo_revision())
